<?php
/*
 +----------------------------------------------------------------------
 + Title        : ArticleCate 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2021/3/2 6:57
 + Last-time    : 2021/3/2 6:57+ chen2
 + Desc         : ArticleCate
 +----------------------------------------------------------------------
*/


namespace app\admin\controller;


use app\common\service\ArticleCateService;
use app\common\validate\ArticleCateValidate;
use think\App;

use function get_client_id;

class ArticleCateController extends AdminBaseController {
	protected $service;
	protected $validate;

    public function __construct(App $app) {
        parent::__construct($app);
		$this->service = new ArticleCateService();
		$this->validate = new ArticleCateValidate();
	}

	public function index(){
		$data = $this->getParams();
		$this->validate->extractScene($data , 'index')->failException(true)->check($data);
		$result = $this->service->getArticleCateList($data);
		return $this->returnSuccess($result);
	}

	public function save(){
		$data = $this->getParams();
		$data['admin_uuid'] = get_client_id();
		$this->validate->extractScene($data , 'save')->failException(true)->check($data);
		$this->service->addArticleCateItem($data);
		return $this->returnSuccess();
	}

	public function update(){
		$data = $this->getParams();
		$this->validate->extractScene($data , 'update')->failException(true)->check($data);
		$this->service->setArticleCateItem($data);
		return $this->returnSuccess();
	}

	public function read(){
		$data = $this->getParams();
		$this->validate->extractScene($data , 'read')->failException(true)->check($data);
		$result = $this->service->getArticleCateItem($data['id']);
		return $this->returnSuccess($result);
	}

	public function delete(){
		$data = $this->getParams();
		$this->service->delArticleCateItem($data['id']);
		return $this->returnSuccess();
	}
}